<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/06/07
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加水果信息</title>
    <style>
        /*td {*/
        /*    text-align: right;*/
        /*}*/
    </style>
</head>
<body>

<form action="AddServlet" method="get">
    <table align="center">
        <tr>
            <th colspan="2">添加水果信息</th>
        </tr>
        <tr>
            <td>类别:</td>
            <td><input type="text" class="" name="type"></td>
        </tr>
        <tr>
            <td>品种:</td>
            <td><input type="text" class="" name="breed"></td>
        </tr>
        <tr>
            <td>产地:</td>
            <td><input type="text" class="" name="area"></td>
        </tr>
        <tr>
            <td>总重量(公斤):</td>
            <td><input type="text" class="" name="weight"></td>
        </tr>
        <tr>
            <td>单价(元/公斤):</td>
            <td><input type="text" class="" name="price"></td>
        </tr>
        <tr>
            <td>简介:</td>
            <td><textarea class="" name="brief" rows="4" cols="24"></textarea>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <button>添加</button>
            </td>

        </tr>

    </table>


</form>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(function () {
        $("form").submit(function () {
            var isSub = true;
            var isFocus = false;
            $("input[type='text']").each(function () {
                if ($(this).val() == "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            $("select").each(function () {
                if ($(this).val() == "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            $("textarea").each(function () {
                if ($(this).val() == "") {
                    if (!isFocus) {
                        $(this).focus();
                        isFocus = true;
                    }
                    isSub = false;
                }
            });
            if (!isSub) {
                alert("此输入框不能为空!");
                return false;
            }

            // var dataFormat = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
            // var flag = dataFormat.test($(".createDate").val());
            // if (!flag) {
            //     alert("日期格式错误，请重新输入!");
            //     $(".createDate").focus();
            //     return false;
            // }

        });

    })

</script>
</body>
</html>
